home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / LGP250S1.ZIP / src / libgplus.5 / libgplus / vms / fndvec.c < prev    next >
C/C++ Source or Header  |  1992-05-03  |  6KB  |  224 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. char * strchr(const char *, char);
  5.  
  6. struct vector{
  7.     char    flag;    /* indicates if this has been commented out */
  8.     char*    name;
  9.     struct    vector*    next;};
  10.  
  11. FILE    *marfile;
  12. FILE    *libfile;
  13. char    line[140];
  14. struct    vector*    vlist = (struct vector*) NULL;
  15. struct  vector* vpoint;
  16. struct  vector* vend = (struct vector*) NULL;
  17. int    vcount=0;
  18. int    vmax=0;    /* maximum number of transfer vectors */
  19.         /* this is used to reserve space for this many vectors*/
  20.  
  21. #ifndef GSMAJOR
  22. #define GSMAJOR 0
  23. #endif
  24.  
  25. #ifndef GSMINOR
  26. #define GSMINOR 0
  27. #endif
  28.  
  29. int    gmajor = GSMAJOR;
  30. int    gminor = GSMINOR;
  31.  
  32. readmar(){
  33.     char    *status;
  34.     char    *pnt;
  35.     int    cmpr;
  36.     int flag;
  37.     do{
  38.     status=fgets(line,sizeof(line),marfile);    
  39.     if(status==(char*) NULL) break;
  40.     cmpr=strncmp(line,"VMAX=",5);
  41.     if(cmpr==0){
  42.         pnt=line+5;
  43.         sscanf(pnt,"%d",&vmax);};
  44.     cmpr=strncmp(line,"    .IDENT    ",8);
  45.     if(cmpr==0){
  46.         pnt=line+8;
  47.         sscanf(pnt,"/%d-%d/",&gmajor,&gminor);};
  48.     flag = 0;
  49.     if(line[0] == ';') flag = 1; 
  50.     cmpr=strncmp(line+flag,"UNUSED",6);
  51.     if(cmpr == 0){
  52.         flag += 2;
  53.         add_unused();
  54.         continue;
  55.         };
  56.     cmpr=strncmp(line+flag,"ROUTINE ",8);
  57.     if(cmpr!=0) continue;    /* test for anything but the routine name */
  58.     pnt=strchr(line,'\n');
  59.     if(pnt!=(char*) NULL) *pnt='\0';
  60.     pnt=line+8+flag;
  61.     checkvec(pnt,0,flag);    /* add this vector to the list*/
  62.     }while(1==1);
  63. }
  64.  
  65. readlib(){
  66.     char    *status;
  67.     char    *pnt;
  68.     char    *epnt;
  69.     char    module[32];
  70.     int    i;
  71.     int    cmpr;
  72.     for(i=0;i<8;i++) {
  73.         status=fgets(line,sizeof(line),libfile);
  74.         if(status==(char*)NULL) return 0;};
  75.     do{
  76.       status=fgets(line,sizeof(line),libfile);
  77.       if(status==(char*) NULL) break;
  78.       pnt=strchr(line,'\n');
  79.       if(pnt!=(char*) NULL) *pnt='\0';
  80.       if(strlen(line)==0) continue;    /* and delete blank lines*/
  81.       cmpr=strncmp(line,"Module ",7);
  82.       if(cmpr==0){
  83.         printf("%s ",line);
  84.         continue;};
  85.       pnt=line;
  86.       do{
  87.         epnt=module;
  88.         while((*pnt!=' ')&&(*pnt!='\0')) *epnt++=*pnt++;
  89.         *epnt='\0';
  90.         checkvec(module,1,0);    /*see if this vector belongs on the list*/
  91.         while(*pnt==' ') pnt++;    /* trim the spaces inbetween the names*/
  92.         if(strlen(pnt)==0) break;
  93.       }while(1==1);
  94.     }while(1==1);
  95.     return 1;
  96. }
  97.  
  98. add_unused(){
  99.     vpoint=(struct vector*) calloc(sizeof(struct vector),1);
  100.     if(vlist==(struct vector*) NULL)
  101.         vlist=vpoint;
  102.     else
  103.         vend->next=vpoint;
  104.     vend=vpoint;
  105.     vend->name="\0";
  106.     vend->flag = 2;
  107. }
  108.  
  109. checkvec(char* pnt,int cflag,int commflag){
  110.     int i;
  111.     vpoint=vlist;
  112. /* We do not need external visibility for the CTOR and DTOR lists. */
  113.     if(strncmp(pnt,"_GLOBAL_.",9) == 0) return;
  114. /* These two entry points are not used in the sharable image library.  */
  115.     if(strncmp(pnt,"_VT.",4) == 0) commflag |= 4;
  116.     if(strncmp(pnt,"__LIBGXX_DEFINED_",17) == 0) commflag |= 4;
  117.     if(strcmp(pnt,"__MAIN") == 0) return;
  118.     if(strcmp(pnt,"_GXX_VMS_STARTUP_2") == 0) return;
  119.     if((cflag==1)&&(vpoint!=(struct vector*) NULL)){
  120.       do{
  121.         if(strcmp(pnt,vpoint->name)==0) return;
  122.          vpoint=vpoint->next;
  123.        }while(vpoint!=(struct vector*) NULL);};
  124. /*     if(cflag==1) printf("\n Adding %s",pnt);*/
  125.     vpoint=(struct vector*) calloc(sizeof(struct vector),1);
  126.     if(vlist==(struct vector*) NULL)
  127.         vlist=vpoint;
  128.     else
  129.         vend->next=vpoint;
  130.     vend=vpoint;
  131.     vend->name=(char*) malloc(strlen(pnt)+1);
  132.     vend->flag = commflag;
  133.     strcpy(vend->name,pnt);
  134.     vcount++;
  135. }
  136.  
  137. writemar(char* pnt){
  138.     char    title[30];
  139.     char*    i;
  140.     strncpy(title,pnt,30);
  141.     i=strchr(title,'.');
  142.     if(i!=(char*) NULL) *i='\0';    /*fix up the title*/
  143.     fprintf(marfile,";\n");
  144.     fprintf(marfile,"    .TITLE  %s\n",title);
  145.     fprintf(marfile,"    .IDENT    /%d-%4.4d/\n",gmajor,gminor);
  146.     if(vmax==0){
  147.         vmax=1;
  148.         while(vmax<vcount) vmax <<= 1;
  149.         vmax <<=1;        /* one more for good measure */
  150.         };
  151.     fprintf(marfile,"VMAX=%d\n",vmax);
  152.     fprintf(marfile,"; This program was generated automatically by the sharable library building program\n");
  153.     fprintf(marfile,"; This MACRO program was lifted verbatim from pages 5-9 and 5-10 of:\n");
  154.     fprintf(marfile,";       Guide to Creating Modular Procedures on VAX/VMS\n");
  155.     fprintf(marfile,";\n");
  156.     fprintf(marfile,"        .MACRO  ROUTINE NAME\n");
  157.     fprintf(marfile,"        .EXTRN          NAME\n");
  158.     fprintf(marfile,"        .ALIGN  QUAD\n");
  159.     fprintf(marfile,"        .TRANSFER       NAME\n");
  160.     fprintf(marfile,"        .MASK           NAME\n");
  161.     fprintf(marfile,"        JMP             NAME+2\n");
  162.     fprintf(marfile,"        .ENDM\n");
  163.     fprintf(marfile,";\n");
  164.     fprintf(marfile,"        .MACRO  UNUSED    NAME\n");
  165.     fprintf(marfile,"    .long    0\n");
  166.     fprintf(marfile,"    .long    0\n");
  167.     fprintf(marfile,"        .ENDM\n");
  168.     fprintf(marfile,";\n");
  169.     fprintf(marfile,"        .PSECT  $$$$%s PIC, USR, CON, REL, LCL, SHR, -\n",title);
  170.     fprintf(marfile,"                            EXE, RD, NOWRT, QUAD\n");
  171.     fprintf(marfile,";\n");
  172.     fprintf(marfile,"; Add new routines only to the bottom of the list!!!\n");
  173.     fprintf(marfile,";\n");
  174.     fprintf(marfile,"lstart:\n");
  175.     vpoint=vlist;
  176.       do{
  177.         if((vpoint->flag & 4) == 4) {
  178.             fprintf(marfile,";UNIVERSAL = %s\n",vpoint->name);
  179.              vpoint=vpoint->next;
  180.         continue;
  181.         };
  182.         if((vpoint->flag & 1) == 1) fprintf(marfile,";");
  183.         if((vpoint->flag & 2) == 2) fprintf(marfile,"UNUSED\n");
  184.         else
  185.           fprintf(marfile,"ROUTINE %s\n",vpoint->name);
  186.          vpoint=vpoint->next;
  187.        }while(vpoint!=(struct vector*) NULL);
  188.     fprintf(marfile,"lend:    .REPEAT VMAX - <<lend - lstart>/8>\n");
  189.     fprintf(marfile,"    .long    0\n");
  190.     fprintf(marfile,"    .long    0\n");
  191.     fprintf(marfile,"    .ENDR\n");
  192.     fprintf(marfile,"    .END\n");
  193. }
  194.  
  195. main(int argc,char *argv[]){
  196.     int nvec1;
  197.     if(argc<2){
  198.         printf(" Usage: fndvec marfile liblistfile");
  199.         exit(1);};
  200.     marfile=fopen(argv[1],"r");
  201.     libfile=fopen(argv[2],"r");
  202.     readmar();
  203.     fclose(marfile);
  204.     printf(" There were %d transfer vectors in the old file.\n",vcount);
  205.     nvec1=vcount;
  206.     readlib();
  207.     fclose(libfile);
  208.     printf(" There were %d transfer vectors after reading the library list.\n",vcount);
  209.     if(nvec1==vcount){
  210.          printf("There were no new vectors  - file not written.\n");
  211.         return 1;};
  212.     if(vcount>vmax && vmax != 0){
  213.     printf("The number of transfer vectors has exceeded the number of positions allocated.\n");
  214.     printf("This version of the library will NOT be compatible with previous versions.\n");
  215.     gmajor++;
  216.     gminor=0;
  217.     vmax=0;};
  218.     if (vmax != 0) gminor++;
  219.     marfile=fopen(argv[1],"w");
  220.     writemar(argv[1]);
  221.     fclose(marfile);
  222.     return 1;
  223. }
  224.